<?php
class ModelCatalogInformationList extends Model {
			
	public function getTotalInformations() {
		$query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "information i where  i.information_id>5");

		return $query->row['total'];
	}
	
	public function getInformations($data = array()) {
		if ($data) {
			$sql = "SELECT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) WHERE  i.information_id>5 and id.language_id = '" . (int)$this->config->get('config_language_id') . "'";

//			$sort_data = array(
//				'i.create_date',
//				'i.sort_order'
//			);		
//
//			if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
//				$sql .= " ORDER BY " . $data['sort'];	
//			} else {
//				$sql .= " ORDER BY id.title";	
//			}
//
//			if (isset($data['order']) && ($data['order'] == 'DESC')) {
//				$sql .= " DESC";
//			} else {
//				$sql .= " DESC";
//			}
			
			$sql .= " ORDER BY i.create_date DESC";	
			
			if (isset($data['start']) || isset($data['limit'])) {
				if ($data['start'] < 0) {
					$data['start'] = 0;
				}		

				if ($data['limit'] < 1) {
					$data['limit'] = 20;
				}	
				
				$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
			}	

			$query = $this->db->query($sql);

			return $query->rows;
		} else {
			$information_data = $this->cache->get('information.' . (int)$this->config->get('config_language_id'));

			if (!$information_data) {
				$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "information i LEFT JOIN " . DB_PREFIX . "information_description id ON (i.information_id = id.information_id) WHERE i.information_id>5 and id.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY id.title");

				$information_data = $query->rows;

				$this->cache->set('information.' . (int)$this->config->get('config_language_id'), $information_data);
			}	

			return $information_data;			
		}
	}
}
?>